﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using InkFx.WinControl;

namespace InkFx.SF.UI
{
    public partial class AssemblyForm : XIDEFrame
    {
        public AssemblyForm()
        {
            InitializeComponent();
        }



        private void AssemblyFormLoad(object sender, EventArgs e)
        {
            Reload();
        }

        private void btnRefreshClick(object sender, EventArgs e)
        {
            Reload();
        }



        public void Reload()
        {
            lvMain.Items.Clear();
            Assembly[] allAssemblys = AppDomain.CurrentDomain.GetAssemblies();
            List<Assembly> listAssembly = new List<Assembly>();

            //过滤掉重复的程序集
            foreach (Assembly assembly in allAssemblys)
            {
                bool find = false;
                foreach (Assembly amy in listAssembly)
                {
                    if (amy != null && amy.FullName == assembly.FullName && amy.ImageRuntimeVersion == assembly.ImageRuntimeVersion)
                    {
                        find = true;
                        break;
                    }
                }
                if (!find)
                    listAssembly.Add(assembly);
            }

            foreach (Assembly amy in listAssembly)
            {
                ListViewItem item = new ListViewItem("");
                item.SubItems.AddRange(new string[] { amy.FullName.IndexOf(",") > 0 ? amy.FullName.Substring(0, amy.FullName.IndexOf(",")) : amy.FullName, amy.Location.Replace(@"/",@"\").Replace(@"\\",@"\") });
                item.ImageIndex = amy.GlobalAssemblyCache ? 0 : 1;
                lvMain.Items.Add(item);
            }
        }



    }
}
